package cn.comtom.ewbs.signature;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication(scanBasePackages = "cn.comtom.ewbs.signature.*")
@ServletComponentScan
@MapperScan("cn.comtom.ewbs.signature.mapper")
@EnableTransactionManagement
@ComponentScan(basePackages = {"cn.comtom.ewbs.signature"})
public class QuickStartApplication extends SpringBootServletInitializer{
	
	public static ConfigurableApplicationContext ac;
	
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(QuickStartApplication.class);
    }
	
    public static void main(String[] args) {
    	QuickStartApplication.ac = SpringApplication.run(QuickStartApplication.class, args);
    }
    
    public static void restart() {
        ApplicationArguments args = ac.getBean(ApplicationArguments.class);
        Thread thread = new Thread(() -> {
        	ac.close();
        	ac = SpringApplication.run(QuickStartApplication.class, args.getSourceArgs());
        });
        thread.setDaemon(false);
        thread.start();
    }
}
